package org.example.demo.controller.userController;

import io.swagger.annotations.ApiOperation;
import org.example.demo.dto.ProductDetail.ProductDetailParam;
import org.example.demo.service.userService.ProductService;
import org.example.demo.service.userService.UserCenterService;
import org.example.mbg.model.Product;
import org.example.mbg.model.Shop;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * 处理商品相关需求
 */
@Controller
@RequestMapping(value = "/user/product")
public class ProductController {
    @Autowired
    private ProductService productService;

    @Autowired
    private UserCenterService userCenterService;

    @ApiOperation("返回商品详情")
    @RequestMapping(value = "/detail")
    @ResponseBody
    public ProductDetailParam detail(Long id, Long user_id) {
        ProductDetailParam res = productService.detail(id);
        res.setIsCollected(userCenterService.getFavs(user_id).stream().anyMatch(e -> e.getShopId().equals(id)));
        return res;
    }
}
